/* 购物车 支付 */
function shopcart_pay() {
    new Vue({
        el:'#shopcart_pay',
        data() {
            return {
                clickClass : [
                    {isTrue : true},
                    {isTrue : false}
                ],
                payParams : JSON.parse(sessionStorage.getItem("payParams")),
                address : {},//地址
                orderPayNumber : urlParam.href().orderPayNumber ,//支付编号
                productName : "",//商品名称
                payAmount : 0,//商品价格
                payType : 0,//支付类型
                loading : false,//loading falg
                payHTML : "",//跳转支付宝HTML代码
            }
        },
        methods : {
            getData(){
                var that = this;
                axios({
                    url : urlParam.domain() + "/api/order/goPayPC",
                    params : {
                        orderPayNumber : that.orderPayNumber,
                        token : urlParam.token(),
                    },
                    method : 'get'
                }).then(result=>{
                    console.log(result);
                    if (result.data.code == -1){
                        that.$message.error(result.data.message);
                    }
                    that.address = result.data.data.address
                    that.productName = result.data.data.productName
                    that.payAmount = result.data.data.payAmount;
                })
            },
            orderTypeClick(index){
                this.payType = index;
                this.clickClass.map((result)=>{
                        result.isTrue = false;
                })
                this.clickClass[index].isTrue = !this.clickClass[index].isTrue;
            },
            payBtn(){
                var that = this;
                // 支付宝
                if (that.payType == 0){
                    axios({
                        url: urlParam.domain() + "/api/ali/createPCPaymentOrder",
                        method: "post",
                        params : {
                            token : urlParam.token(),
                            outTradeNo : that.orderPayNumber
                        }
                    }).then(function (res) {
                        that.payHTML = res.data;
                    })

                }else {

                }
            sessionStorage.removeItem("payParams");
            }
        },
        created() {
            this.getData();
         },
        //修改后执行方法
        updated(){
            if (this.payHTML != ""){
                document.forms[0].submit();
            }
        }
    })
}


/* 支付成功*/
function pay_suc() {
    new Vue({
        el:'#pay_suc',
        data() {
            return {
                orderPayNumber : 0,//支付编号
                payAmount : 0,//商品价格
            }
        },
        methods : {
            getData() {
                var that = this;
                that.orderPayNumber = urlParam.href().payNumber;
                axios({
                    url: urlParam.domain() + "/api/buy/getPayOrderByPayNumber",
                    params: {
                        payNumber: that.orderPayNumber,
                        token: urlParam.token(),
                    },
                    method: 'get'
                }).then(result => {
                    console.log(result);
                    if (result.data.code == -1) {
                        that.$message.error(result.data.message);
                    }
                    that.payAmount = result.data.data.payAmount;
                })
            },
        },
        created() {
            this.getData();
        },
    })
}